import Axios from 'axios'

const myAxios = {}

myAxios.install = function (Vue) {
    // 创建实例时配置默认值
    const myAxiosObj = Axios.create({
        baseURL: 'http://127.0.0.1:8888/api/private/v1'
    });
    
    //添加请求拦截器
    myAxiosObj.interceptors.request.use(function (config) {
        // 在发送请求之前做些什么
        if (config.url !== '/login') {
            const token = JSON.parse(localStorage.getItem('userinfo')).token
            config.headers.Authorization = token
        }
        return config;
    });
    Vue.prototype.$req = myAxiosObj
}
export default myAxios